<template>
  <div class="My">
    <div class="My_top">
      <span>名称： {{user.name}}</span>
      <span>性别： {{user.sex == 1 ? '女' : '男'}}</span>
      <span>学院： {{user.college}}</span>
      <span>班级： {{user.classe}}</span>
      <span>手机： {{user.phoneNum}}</span>
      <span>邮箱： {{user.email}}</span>
    </div>
    <Borrowing :userId="userId"/>

  </div>
</template>

<script>
  import Borrowing from "../components/Borrowing";

  import {apiByIdUser} from "../request/api"

  export default {
    name: "My",
    components: {
      Borrowing
    },
    data() {
      return {
        userId: this.$store.state.userId,
        user: ''
      }
    },
    created() {
      this.init()
    },
    activated() {
      this.init()
    },
    methods: {
      init(){
        if (this.$store.state.userId === '') {
          this.$message({
            message: '请先登录',
            type: 'warning'
          });
          this.$router.push('/login')
        }else{
          apiByIdUser({userId:this.userId}).then(res => {
            this.user = res.data.User
            console.log(res)
          })
        }
      }

    }
  }
</script>

<style scoped>
  .My {
    margin: 100px 0 160px;
  }
  .My_top {
    display: flex;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 100px;
  }
  .My_top > span {
    font-size: 20px;
    width: 40%;
    padding-left: 110px;
    margin-bottom: 40px;
  }
</style>
